<template>
	<view class="body" :style="{backgroundImage: 'url('+imageURL+')',height:screenHeight+'px!important'}">
		<view class="u-form">
			<view class="username">
				<image class="img" src="../../static/party_building/assets/login/admin@2x.png" mode=""></image><input
					v-model="username" placeholder="请输入账户名称"></input>
			</view>
			<view class="password">
				<image class="img" src="../../static/party_building/assets/login/yanzhengma@2x.png" mode=""></image>
					<uni-easyinput type="password"  v-model="password" placeholder="请输入密码"></uni-easyinput>
			</view>
		</view>
		<view class="button">
			<button type="button" @click="submit" class="submit">登&nbsp;录</button>
		</view>
	</view>
</template>
 
<script>
	import {
		login
	} from "@/api/api_login.js"
	import {
		getMenu
	} from "../../api/api_department.js"
	import NetWorkTool from '@/api/netWorkTool'
	export default {
		name: "login",
		data() {
			return {
				username: "",
				password: "",
				imageURL: "../../static/party_building/assets/login/login.jpg",
				screenHeight: '',
				base:'',
				bgImgUrl: ''
			}
		},
		onReady() {
			let _this = this 
			// NetWorkTool.GET('/api/loginBgBase64').then(res=>{
			// 		_this.bgImgUrl = res 
			// 		console.log(_this.bgImgUrl)
			// 		})
			this.getClientHight();
		},
		methods: {
			getClientHight() {
				this.screenHeight = uni.getSystemInfo().windowHeight
			},
			submit() { 
				
				// uni.request({
				// 	'method':"POST",
				//     url: `http://112.124.6.140:8090/sys-user/getUserList`, //仅为示例，并非真实接口地址。
				//     data: { 
				// 	'username': this.username,
				// 	'password': this.password
				// },
				//     header: {
				//         'custom-header': 'hello' //自定义请求头信息
				//     },
				//     success: (res) => {
				//         console.log(res.data);
				//     },
				// 	fail:res=>{
				// 		console.log(res)
				// 	}
				// });
				login({
					'username': this.username,
					'password': this.password
				}).then(res => {
					console.log("then",res)
					const tokenType = 'x-access-token';
					const token = res[tokenType];
					uni.setStorage({
						key: 'AuthToken',
						data: token
					}); 
					uni.setStorage({
						key: 'tokenType',
						data: tokenType
					});
					uni.setStorage({
						key: 'user',
						data: res
					});
					uni.setStorage({
						key: 'menuMap',
						data: res.role
					});
					uni.redirectTo({
						url: "/pages/index/index"
					})
					
				}).catch(res=>{
					console.log(111,res) 
				})
			},
			// 获取背景图
			getBgImg() {
				// NetWorkTool.GET('/api/loginBgBase64').then(res=>{
				// 	this.bgImgUrl =res 
				// });
			}
		}
	}
</script>

<style lang="scss" scoped>
	.button {
		position: absolute;
		width: 100%;
		margin: 120% auto 0 auto;
	}

	.submit {
		width: 80%;
		font-weight: 400;
		color: #FFFFFF;
		font-size: 1rem;
		height: 2.5rem;
		margin-top: 10%;
		background: linear-gradient(0deg, #E20909, #FF534D);
		border-radius: 2.75rem;
	}

	.img {
		height: 40upx;
		width: 40upx;
		margin: auto 0;
		margin-left: 5px;
		margin-right: 10px;
		display: inline-block;
	}

	uni-input {
		width: 70%;
		display: inline-block;
	}

	.username,
	.password {
		width: 70%;
		font-size: 1rem;
		padding: .375rem .625rem;
		margin: 0.375rem auto;
		color: #333;
		smallbox-sizing: border-smallbox;
		// margin: .3125rem .625rem .3125rem .25rem;
		background: none;
		outline: none;
		border: none;
		opacity: .4;
		background-color: rgb(232, 240, 254) !important;
		/deep/ .uni-easyinput{
			width: 80%;
			display: inline-block;
		}
	}

	.u-form {
		width: 100%;
		margin: 90% auto 0 auto;
		position: absolute;
	}

	.body {
		width: 100%;
		height: 100%;
		background: no-repeat fixed ceter;
		background-size: 150%;
		/* 0％~100％之间的任何值，将背景图片宽高按百分比显示，当设置一个值的时候同也将其作为图片宽度来等比缩放 */
		background-size: cover;
		/* 将背景图片等比缩放填满整个容器 */
	}
</style>
